package com.example.mengxuegu.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

/**
 * @program: springboot-mengxuegu
 * @description: 测试入口
 * @author: XianJin.Lu
 * @create: 2021-08-19 19:24
 **/
@RestController
public class Testcontroller {
    @Autowired
    JdbcTemplate jdbcTemplate;


    @RequestMapping("/test/01")
    public List<Map<String,Object>> test01(){
        /*不用实体类 直接用map集合接受也可以*/
         String sql="select * from emp";
        List<Map<String, Object>> maps = jdbcTemplate.queryForList(sql);

        return maps;
    }

    @RequestMapping("/test/{id}")
    public String test02(@PathVariable("id") int id){
        String sql="update emp set name=?  where id="+id;
        Object[] objects=new Object[1];
        objects[0]="鲁大师";
        jdbcTemplate.update(sql,objects);
        return "ok";
    }

}
